/**********************************************************************************************/
// dgt_LogicTable.h
//
// Common Lib for Digital Studio
// Block of management of bool functions
// Class of logic table
//
// Copyright Diamant Group 2008
/**********************************************************************************************/
#ifndef _DGT_LOGICTABLE_H_
#define _DGT_LOGICTABLE_H_

#include "dgtKernel.h"
#include "dgt_SmartMacros.h"
#include <map>

using namespace std;

SMART_CLASS( dgt_LogicTable );

WX_DECLARE_OBJARRAY( dgt_LogicTable_Ptr, dgt_LogTableArray ); 

/**********************************************************************************************/
/**
* \brief Class for representation of logic table for boolean function.
*/
class dgt_LogicTable
{
	public://///////////////////////////////////////////////////////////////////////////////////

		/**
		* @brief Ctor as default
		*/
							dgt_LogicTable( );

		/**
		* @brief Ctor 
		* @param inVarNames array of variables of logic table
		*/
							dgt_LogicTable( wxArrayString &inVarNames );

		/**
		* @brief Ctor 
		* @param inVarNames array of variables of logic table
		* @param inValues array of values
		*/
							dgt_LogicTable( wxArrayString &inVarNames,
											map<unsigned,bool> inValues );

		/**
		* @brief Dtor as default
		*/
virtual						~dgt_LogicTable()							{};

	public://///////////////////////////////////////////////////////////////////////////////////

		/**
		* @brief Function for setting array of variables in logic table
		* @param inVarNames New array
		* @throw DGTEXC_LOGTABLE_INCORRECTSIZE If size of inVarNames is incorrect
		*/
		void				set_VarNames( wxArrayString &inVarNames );

		/**
		* @brief Function for getting array of variables in logic table
		* @return Array of variables
		*/
		wxArrayString		get_VarNames( void )		{ return m_VarNames; }


		/**
		* @brief Function for setting name of one variable
		* @param inIndex Index of variable
		* @param inVarName New name of variable
		* @throw DGTEXC_LOGTABLE_INCORRECTINDEX If index inIndex is incorrect
		*/
		void				set_VarName( unsigned inIndex, wxString &inVarName );

		/**
		* @brief Function for getting name of one variable
		* @param inIndex index of varible
		* @return Name of variable with index InIndex 
		* @throw DGTEXC_LOGTABLE_INCORRECTINDEX If index inIndex is incorrect
		*/
		wxString			get_VarName( unsigned inIndex );

		/**
		* @brief Function for setting whole logic table. NOTE: count of variables must be equal to count of 
				 variables in this logic table	
		* @param inValues New values
		* @throw DGTEXC_LOGTABLE_INCORRECTSIZE If size of inValues is incorrect
		*/
		void				set_Values( map<unsigned, bool> inValues );

		/**
		* @brief Function for getting whole logic table
		* @return Whole logic table
		*/
		map<unsigned, bool>	get_Values( void )				{ return m_Values; }

		/**
		* @brief Function for setting separate value to logic table
		* @param inIndex Input values in a decimal kind
		* @param inValue New value that corresponding to input values
		* @throw DGTEXC_LOGTABLE_INCORRECTINDEX If index inIndex is incorrect 
		*/
		void				set_Value( unsigned inIndex, bool inValue );

		/**
		* @brief Function for getting separate value to logic table
		* @param inIndex Input values in a decimal kind
		* @return Value of function that corresponding to inIndex
		* @throw DGTEXC_LOGTABLE_INCORRECTINDEX If index inIndex is incorrect 
		*/
		bool				get_Value( unsigned inIndex );

		/**
		* @brief Function for setting separate value to logic table
		* @param inIndex Input values as bool array 
				( f.e - [0] element of index = 0, [1] element = 1 and [2] element = 1, then function will 
				set element with index 110 )
		* @param inValue New value that corresponding to input values
		* @throw DGTEXC_LOGTABLE_INCORRECTINDEX If index inIndex is incorrect 
		*/
		void				set_Value( wxBoolArray inIndex, bool inValue );

		/**
		* @brief Function for setting separate value to logic table
		* @param inIndex Input values as bool array 
				( f.e - [0] element of index = 0, [1] element = 1 and [2] element = 1, then function will 
				return element with index 110 )
		* @return Value that corresponding to input values
		* @throw DGTEXC_LOGTABLE_INCORRECTINDEX If index inIndex is incorrect 
		*/
		bool				get_Value( wxBoolArray inIndex );

		/**
		* @brief Function for deleting variable in logic table
				NOTE: It will change logic table!
		* @param inIndex index of variable to delete
		* @param inValuetoReplace value, which will replace function result
				( f.e. - in function f was three variables x, y, z. f(0, 0, 0 ) = 0 and f( 0, 0, 1) = 1.
				User want to delete variable z. If inValuetoReplace = 1, than f( 0, 0 ) will be equal to f( 0, 0, 1 ),
				if 0, than to f( 0, 0, 0 ).
		* @throw DGTEXC_LOGTABLE_INCORRECTINDEX If index inIndex is incorrect 
		*/
		void				DeleteVar( unsigned inIndex, bool inValuetoReplace = false );

		/**
		* @brief Function for adding variable to logic table				
		* @param inName name of variable to add
		* @param inValuetoFill value, wich will fill new empty results of function
		* @throw DGTEXC_LOGTABLE_INCORRECTINDEX If index inIndex is incorrect 
		* @throw DGTEXC_LOGTABLE_INCORRECTNAME if inName is not unique
		*/
		void				AddVar( wxString inName, bool inValuetoFill = false );

		/**
		* @brief Function for getting count of variables				
		* @return Count of variables of logic table
		*/
		unsigned			get_VarCount( void )				{ return m_VarCount; }
		
		/**
		* @brief Function for getting count of values in logic table				
		* @return Count of values in logic table
		*/
		unsigned			get_ValuesCount( void )			{ return m_ValuesCount; }


	private:////////////////////////////////////////////////////////////////////////////////////

		void				set_EmptyValues( unsigned count );

	private:////////////////////////////////////////////////////////////////////////////////////

		wxArrayString		m_VarNames;				/*!< array of names of variables */

		/** @brief array of values in logic table 
		*
		* Each element of map - this is a string in the logic table
		* int number - it is the set of entrance values, translated in a decimal kind 
		* bool value - it is a resulting value
		*
		* f.e. - string in logic table will be such:
		* m_Values[3] == false
		* it means that at receipt of entrance signals with values 00000011 ("3" in binary)
		* ( 1 - from source 0, 1 - from source 1, and 0 from others )
		* resulting value will be 0
		*/
		map<unsigned, bool>	m_Values;	

		unsigned			m_VarCount;				/*!< count of variables of function */
		unsigned			m_ValuesCount;			/*!< maximum count of values */
};

#endif // _DGT_LOGICTABLE_H_
